﻿using System;

namespace OrderManagement
{
    public class OrderDetails : IEquatable<OrderDetails>
    {
        public string ProductName { get; set; }
        public int Quantity { get; set; }
        public double UnitPrice { get; set; }
        public double Amount
        {
            get { return Quantity * UnitPrice; }
        }

        public OrderDetails(string productName, int quantity, double unitPrice)
        {
            ProductName = productName;
            Quantity = quantity;
            UnitPrice = unitPrice;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as OrderDetails);
        }

        public bool Equals(OrderDetails other)
        {
            return other != null &&
                   ProductName == other.ProductName;
        }

        public override int GetHashCode()
        {
            return HashCode.Combine(ProductName);
        }

        public override string ToString()
        {
            return $"商品: {ProductName}, 数量: {Quantity}, 单价: {UnitPrice:F2}, 金额: {Amount:F2}";
        }
    }
}